package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmChannelService;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 频道信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2021-11-02
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理api")
public class WmChannelController {

    @Autowired
    private IWmChannelService wmChannelService;

    /**
     * 根据名称模糊查询分页列表
     */
    @ApiOperation(value = "根据名称模糊查询分页列表",notes = "author:lhp") //value 指名称 notes 备注
    //name  接收参数名
    //value   接收参数的意义描述
    //required   参数是否必填
    //dataType   参数的数据类型 只作为标志说明，并没有实际验证
    //
    @ApiImplicitParam(name = "dto",value = "查询对象",required = true,dataType = "ChannelDto")
    @PostMapping("/list")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {
        return wmChannelService.listByName(dto);
    }

    /**
     * 新增频道
     */
    @PostMapping
    @ApiOperation(value = "新增频道",notes = "author:lhp")
    @ApiImplicitParam(name = "channel",value = "频道对象",required = true,dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel channel){
        return wmChannelService.saveChannel(channel);
    }

    /**
     * 编辑修改
     */
    @PutMapping()
    @ApiOperation(value = "修改频道",notes = "author:lhp")
    @ApiImplicitParam(name = "channel",value = "频道对象",required = true,dataType = "WmChannel")
    public ResponseResult updateChannel(@RequestBody WmChannel channel){
        return wmChannelService.updateChannel(channel);
    }

    /**
     * 删除
     */
    @DeleteMapping("/{channelId}")
    @ApiOperation(value = "删除频道",notes = "author:lhp")
    @ApiImplicitParam(name = "channelId",value = "频道Id",required = true,dataType = "Long")
    public ResponseResult updateChannel(@PathVariable Long channelId){
        return wmChannelService.deleteChannel(channelId);
    }

    //查询所有的频道
    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }
}
